package com.aia.prm.web.qne;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.util.StringUtils;

import com.aia.prm.service.DefaultService;
import com.cfh.ahead.Constant;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings({ "serial", "rawtypes" })
public class CorpTypaAction extends ActionSupport implements SessionAware {
	private static final Logger logger = Logger.getLogger(CorpTypaAction.class);

	private Map session;
	private String validate;
	
	private DefaultService defaultService;
	
	private String address;

	private String base;

	private String birth;

	private String name;

	private String pho;

	private String w_name;
	
	private String from;

	public String execute() {
		defaultService.updateQneTypa(this);
		return SUCCESS;
	}

	public String getAddress() {
		return address;
	}

	public String getBase() {
		return base;
	}

	public String getBirth() {
		return birth;
	}

	public DefaultService getDefaultService() {
		return defaultService;
	}

	public String getName() {
		return name;
	}

	public String getPho() {
		return pho;
	}
	public String getValidate() {
		return validate;
	}
	public String getW_name() {
		return w_name;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void setBase(String base) {
		this.base = base;
	}
	public void setBirth(String birth) {
		this.birth = birth;
	}

	public void setDefaultService(DefaultService defaultService) {
		this.defaultService = defaultService;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPho(String pho) {
		this.pho = pho;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public void setValidate(String validate) {
		this.validate = validate;
	}

	public void setW_name(String w_name) {
		this.w_name = w_name;
	}

	public void validate() {
		try {
			{// 较验验证码
				String imgCode = (String) session.get(Constant.CAPTCHA_SESSION_HOLDER);
				if (!StringUtils.hasText(imgCode)) {
					addFieldError("imageCode", "请再次获取图片验证码");
					return;
				}

				if (!StringUtils.hasText(getValidate())) {
					addFieldError("imageCode", "请输入图片验证码");
					return;
				}
				if (!getValidate().toLowerCase().equals(imgCode)) {
					addFieldError("imageCode", "验证码输入错误");
					return;
				}
			}

		} catch (Exception e) {
			addFieldError("SERVER_ERROR", "未知错误");
			logger.error("" + e, e);
		}

	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

}
